package de.karlNet.sambamanager.ldapController.commands;

import java.io.UnsupportedEncodingException;

import javax.naming.NamingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.commands.attributeBuilder.UserAttributeBuilder;
import de.karlNet.sambamanager.ldapModel.LdapUser;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class ModifyUser extends BaseCommand {
	@Autowired
	private UserAttributeBuilder userAttributeBuilder;

	public void modifyUserItSelf(LdapUser ldapUser) throws NamingException,
			UnsupportedEncodingException {
		SimpleModificationCommand modificationCommand = new SimpleModificationCommand(
				this.ldapTemplate, ldapUser.getDn());
		modificationCommand.simpleModification(this.userAttributeBuilder
				.buildUserAttributeList(ldapUser));
		modificationCommand.execute();
		this.resetTrees();
	}
}
